<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col>
          <el-button type="primary">添加用户</el-button>
        </el-col>
      </el-row>
      <el-table :data="roleData">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-row
              v-for="(item, i1) in scope.row.children"
              :key="item.id"
              :class="['tag-top', i1 === 0 ? '' : 'tag-bottom']"
            >
              <el-col :span="5">
                <el-tag>{{ item.authName }}</el-tag>
              </el-col>
              <el-col :span="19">
                <el-col :span="5">
                  <!-- <el-tag v-for="item1 in item" :key="item1.id">{{
                  item1.authName
                }}</el-tag> -->
                </el-col>
                <el-col :span="14"></el-col>
              </el-col>
            </el-row> </template
        ></el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="roleName" label="角色名称"></el-table-column>
        <el-table-column prop="roleDesc" label="角色描述"></el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" size="mini">编辑</el-button>
            <el-button type="danger" size="mini">删除</el-button>
            <el-button type="warning" size="mini">操作</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      roleData: []
    }
  },
  created() {
    this.getRoleData()
  },
  methods: {
    async getRoleData() {
      const { data: res } = await this.$http.get('roles')
      // console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error('获取角色失败')
      }
      this.roleData = res.data
    }
  }
}
</script>

<style scoped>
.el-card {
  margin-top: 10px;
}
.el-tag {
  margin: 7px;
}
.tag-top {
  border-top: 1px solid #eee;
}
.tag-bottom {
  border-bottom: 1px solid #eee;
}
</style>
